<?php

declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreatePayPingTableMigration extends AbstractMigration
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change(): void
    {
        $this->table('pay_ping', ['id' => false, 'primary_key' => ['id']])
            ->addColumn('id', 'integer', ['identity' => true])
            ->addColumn('user_id', 'integer', ['null' => true])
            ->addColumn('biz_id', 'integer', ['null' => true,'default' => 0,'comment' => '商家ID'])
            ->addColumn('goods_id', 'integer', ['null' => true,'default' => 0,'comment' => '商品ID'])
            ->addColumn('item_id', 'integer', ['null' => true,'default' => 0,'comment' => '相关ID'])
            ->addColumn('type', 'string', ['limit' => 16,'null' => true,'default' => 'pay','comment' => '类型'])
            ->addColumn('star', 'integer', ['limit' => 11,'null' => true,'default'=>5,'comment' => '评分'])
            ->addColumn('content', 'string', ['limit' => 255,'null' => true,'comment' => '评论'])
            ->addColumn('created_at', 'datetime', ['null' => true,'comment' => '创建时间'])
            ->addColumn('updated_at', 'datetime', ['null' => true,'comment' => '更新时间'])
            ->addIndex(['user_id', 'biz_id', 'type'], ['unique' => true])
            ->create();
    }
}
